<template>
  <div>
    <el-dialog class="bg-white-dialog" :visible.sync="showDialog" width="1190px" :close-on-click-modal="false" :close-on-press-escape="false">
      <div slot="title">
        <div class="flex justify-between align-center padding-right-30">
          <div>
            <span class="color-333333 font-size-18 font-weight-700 padding-right-20">收缴率</span>
            <span class="color-666666">单位：万元</span>
          </div>
          <div>
            <span class="color-666666 padding-right-20">财年&nbsp;{{ fiscalYear }}</span>
            <span class="color-666666">日期&nbsp;{{ fiscalYear }}-{{ fiscalMonth }}-{{ fiscalDay }}</span>
          </div>
        </div>
      </div>

      <el-table class="has-bg" :data="tableData.slice(0, 1)" style="width: 100%" :show-header="true" :border="true">
        <el-table-column align="left" prop="projectName" label="" :min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.projectKey && scope.row.projectKey != 'group'" class="cursor-pointer-line padding-left-10" 
                  @click="goInfo(scope.row)">{{ scope.row.projectName }}</span>
            <span v-else class="cursor-pointer-line padding-left-10" @click="goInfo(scope.row)">{{ scope.row.projectName }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="收缴率">
          <template #header>
            <span>收缴率</span>
            <span v-tooltip="'收缴率'" class="icon el-icon-question padding-left-5"></span>
          </template>
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.collectionRate | accMul }}%</span>
          </template>
        </el-table-column>
        <el-table-column align="center">
          <template #header>
            <span>欠费资产个数</span>
            <span v-tooltip="'欠费资产个数'" class="icon el-icon-question padding-left-5"></span>
          </template>
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.arrearageAssetCount }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" class-name="head1">
          <template #header>
            <span>总欠费金额</span>
            <span v-tooltip="'总欠费金额（万元）'" class="icon el-icon-question padding-left-5"></span>
          </template>
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.arrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" class-name="head2">
          <template #header>
            <span>欠费超过押金</span>
            <span v-tooltip="'欠费超过押金'" class="icon el-icon-question padding-left-5"></span>
          </template>
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ (scope.row.arrearsExceedDeposit || 0) | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="30天以内欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.leArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="30-90天欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.betweenArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="超过90天欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.geArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
      </el-table>

      <el-table class="margin-top-10" :data="tableData.slice(1)" style="width: 100%" :show-header="false" :border="true">
        <el-table-column align="left" prop="projectName" label="" :min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.projectKey && scope.row.projectKey != 'group'" class="cursor-pointer-line padding-left-10" @click="goInfo(scope.row)">{{ scope.row.projectName }}</span>
            <span v-else class="padding-left-10">{{ scope.row.projectName }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="收缴率">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.collectionRate | accMul }}%</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="欠费资产个数">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.arrearageAssetCount }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="总欠费金额（万元）" class-name="head1">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.arrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="欠费超过押金" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ (scope.row.arrearsExceedDeposit || 0) | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="30天以内欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.leArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="30-90天欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.betweenArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="超过90天欠费金额" class-name="head2">
          <template slot-scope="scope">
            <span class="cursor-pointer-line" @click="goInfo(scope.row)">{{ scope.row.geArrearageAmount | moneyFilterNoUnit }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
  import dayjs from 'dayjs';
  import { apiCollectionRateDetail } from '@a/about';

  export default {
    props: {
      selectTime: {
        type: Number,
        default: 0,
      },
      universalParams:{
        type:Object,
        default:()=>{
          return {}
        }
      }
    },

    computed: {
      fiscalYear() {
        return dayjs(this.selectTime).format('YYYY');
      },
      fiscalMonth() {
        let date = dayjs(this.selectTime).format('YYYY-MM-DD');
        let month = date.split('-')[1];
        return Number(month);
      },
      fiscalDay() {
        let day = new Date(new Date(this.fiscalYear, this.fiscalMonth).setDate(0)).getDate();
        return day
      },
    },

    data() {
      return {
        showDialog: false,
        tableData: [],
      };
    },

    methods: {
      init() {
        this.getData();
        this.showDialog = true;
      },

      async getData(){
        let res = await apiCollectionRateDetail(this.universalParams)
        this.tableData = res.rows || []
      },

      goInfo(row, type) {
        let pathName = '';
        let planName = '';
        let planProjectName = '';
        if (row.projectKey == "group") {
          pathName = 'groupmonth-all-plan';
          planName = '集团月报'; //集团月报
          planProjectName = "集团"
        } else {
          pathName = 'execute-all-plan';
          planName = '项目月报'; //项目月报
          planProjectName = row.projectName
        }

        let queryData = {
          headerName: planName,
          year: this.fiscalYear || '',
          month: this.fiscalMonth,
          planProjectName:planProjectName
        };

        if (row.projectKey && row.projectKey != "group") {
          queryData.projectKey = row.projectKey
        }

        let pathUrl = {
          name: pathName,
          query: queryData,
        };

        let { href } = this.$router.resolve(pathUrl);
        window.open(href);
      },
    },
  };
</script>

<style lang="scss" scoped>
  ::v-deep .el-table {
    th .cell{
      font-size: 14px;
      padding: 0 3px;
    }

    .el-table__header-wrapper {
      .head1 {
        background: rgba(247, 145, 0, 0.25) !important;
      }
      .head2 {
        background: rgba(247, 145, 0, 0.1) !important;
      }
    }
  }

  ::v-deep .has-bg{
    .el-table__body-wrapper{
        .el-table__row{
            background: rgba(51,132,254,0.2);
        }
    }
  }
</style>
